package cn.edu.sjtu.dfa;

public class Move extends Instruction {
	private DataContainer end;
	private DataContainer start;
	
	public Move(DataContainer v1, DataContainer v2) {
		end = v1;
		start = v2;
	}
	
	public DataContainer getStart() {
		return start;
	}
	
	public DataContainer getEnd() {
		return end;
	}

	@Override
	public String toString() {
		String ss = "", es = "";
		if (start instanceof Register) {
			ss = "v" + ((Register)start).getRegister();
		} else if (start instanceof ArrayValue) {
			ss = ((ArrayValue)start).getArrayRef() + "[" + ((ArrayValue)start).getIndex() + "]";
		} else {
			ss = ((ObjectValue)start).getArrayRef() + "." + ((ObjectValue)start).getIndex();
		}
		if (end instanceof Register) {
			es = "v" + ((Register)end).getRegister();
		} else if (end instanceof ArrayValue) {
			es = ((ArrayValue)end).getArrayRef() + "[" + ((ArrayValue)end).getIndex() + "]";
		} else {
			es = ((ObjectValue)end).getArrayRef() + "." + ((ObjectValue)end).getIndex();
		}
		return "Move " + ss + " to " + es;
	}
}
